// The Vue build version to load with the `import` command
// (runtime-only or standalone) has been set in webpack.base.conf with an alias.
import Vue from 'vue'
import App from './App'
import router from './router'
import Vant from 'vant'
import store from './store'

import Axios from './axios.config' // 引入全局请求组件
import 'vant/lib/index.css'

import VideoPlayer from 'vue-video-player'
import '../node_modules/video.js/dist/lang/zh-CN'
import '../node_modules/video.js/dist/video-js.css'
import '../node_modules/vue-video-player/src/custom-theme.css'

Vue.use(Vant)
Vue.use(VideoPlayer)
Vue.prototype.$axios = Axios

Vue.prototype.$baseUrl = 'http://39.106.139.151:7676/' // 静态资源根路径

Vue.config.productionTip = false
Vue.filter('imgPath', (value) => {
  const firstChar = value ? value.substr(0, 1) : ''
  if (firstChar === '/' || firstChar === 'u') {
    return 'http://39.106.139.151:7676/' + value
  } else {
    return value || require('@/assets/img/news.png')
  }
})

router.beforeEach((to, from, next) => {
  const token = window.localStorage.getItem('token')
  if (to.name !== 'login' && !token) {
    router.push({
      name: 'login'
    })
  } else if (to.name === 'login' && token) {
    router.push({
      path: '/'
    })
  } else {
    next()
  }
})
/* eslint-disable no-new */
new Vue({
  el: '#app',
  store,
  router,
  components: { App },
  template: '<App/>'
})
